package cn.golxen.barcode.controller;

import cn.golxen.barcode.entity.BarcodeInfo;
import cn.golxen.barcode.service.BarcodeService;
import cn.golxen.commons.entity.Result;
import cn.golxen.commons.vo.BarcodeInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/barcode")
public class BarcodeController {

    @Autowired
    private BarcodeService barcodeService;



    @GetMapping(value = "/info")
    public BarcodeInfoVo getBarcodeInfo(@RequestParam String url){
        BarcodeInfo barcodeInfo= barcodeService.getBarcodeInfo(url);
//        return new Result(201,"添加商品",barcodeInfo);
        BarcodeInfoVo barcodeInfoVo=new BarcodeInfoVo();
        BeanUtils.copyProperties(barcodeInfo,barcodeInfoVo);
        return barcodeInfoVo;
    }

    @GetMapping(value = "/code")
    public String getCode(@RequestParam String url){
        return barcodeService.getCode(url);
    }


    @GetMapping(value = "/info/{code}")
    public BarcodeInfoVo getBarcodeInfoByCode(@PathVariable String code){
        return barcodeService.getBarcodeInfoByCode(code);
    }

}
